import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
// import HelloWorld from '@/components/HelloWorld'
import home from '@/views/home'
import _class from '@/views/class/class'
import _questionDetail from '@/views/class/questionDetail'
import _callName from '@/views/class/callName'
import _notOrder from '@/views/notOrder'
import _correctRate from '@/views/class/correctRate'
import _particeRate from '@/views/class/particeRate'
import _raceAnswer from '@/views/class/raceAnswer'
import _timeLine from '@/views/class/timeLine'
import _exercise from '@/views/exercise/index'
import _studydiag from '@/views/studydiag/index'
import _studydiagCodedetail from '@/views/studydiag/codeDetail'
import _wrongbook from '@/views/wrongbook/index'
import wrongbookDetail from '@/views/wrongbook/wrongDetail'
import _userinfo from '@/views/usercenter/userinfo'
import _register from '@/views/usercenter/register'
import _login from '@/views/usercenter/login'
import _homework from '@/views/homework/homework'
import _homeworkHistory from '@/views/homework/history'
import _video from '@/views/video/index'
import _playvideo from '@/views/video/playVideo'

Vue.use(Router)

let router= new Router({
  routes: [
  {
      path: '/notOrder',
      name: 'notOrder',
      component: _notOrder,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/',
      name: 'class',
      component: _class,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/class',
      name: 'class',
      component: _class,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/questionDetail/:day',
      name: '问题详情',
      component: _questionDetail,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/callName/:day',
      name: '点名',
      component: _callName,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/timeLine/:day',
      name: '时光轴',
      component: _timeLine,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/correctRate/:day',
      name: '正确率',
      component: _correctRate,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/particeRate/:day',
      name: '参与率',
      component: _particeRate,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/raceAnswer/:day',
      name: '抢答',
      component: _raceAnswer,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/exercise',
      name: 'exercise',
      component: _exercise,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
    },
    {
      path: '/userinfo',
      name: 'userinfo',
      component: _userinfo,
      meta: {
      	login: true
      }
    },
    {
      path: '/login',
      name: 'login',
      component: _login,
      
    },
    {
      path: '/register',
      name: 'register',
      component: _register,
      
    },
    {
      path: '/wrongbook',
      name: 'wrongbook',
      component: _wrongbook,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
      
    },
    {
      path: '/wrongbook/:subject_type',
      name: '科目错题本',
      component: wrongbookDetail,
      meta:{
      	keepAlive:true,
      	isBack:false
      }
      
    },
    {
      path: '/studyDiagnosis',
      name: 'studyDiagnosis',
      component: _studydiag,
      meta:{
      	keepAlive:true,
      	isBack:false
      }      
    },
    {
      path: '/homework',
      name: 'homework',
      component: _homework,
      meta:{
      	keepAlive:true,
      	isBack:false
      }      
    },
    {
      path: '/homeworkHistory',
      name: '作业本历史记录',
      component: _homeworkHistory,
      meta:{
      	keepAlive:true,
      	isBack:false
      }      
    },
    {
      path: '/studydiagCodedetail/:subjectid/:courseid/:coursename',
      name: '学情诊断的科目详情',
      component: _studydiagCodedetail,
      meta:{
      	keepAlive:true,
      	isBack:false
      }      
    },
    {
      path: '/video',
      name: 'video',
      component: _video,
      meta:{
      	keepAlive:true,
      	isBack:false
      }      
    },
    {
      path: '/playvideo/:vid/:vname',
      name: '播放精品课',
      component: _playvideo,
      meta:{
      	keepAlive:true,
      	isBack:false
      }      
    } 
    
  ]
})

router.beforeEach((to, from, next) => {
  if (to.matched.some((item) => item.meta.login)) {

    store.commit('INIT_STATE')
    if (!store.state.userlogin) {
      router.push({
        path: '/login'
      })

    } else {
      next();
    }
  } else {
    next()
  }
})

export default router;

